import 'package:flutter/material.dart';

import '../../utils/util.dart';
import 'index.dart';
import 'widgets/widgets.dart';

class SingleSelectionPage extends StatelessWidget {
  SingleSelectionPage({Key? key}) : super(key: key);
  final controller = Get.put(SingleSelectionController());
  final state = Get.find<SingleSelectionController>().state;
  // 主视图
  Widget _buildView() {
    return ListView.separated(
        itemBuilder: (ctx, idx) {
          var text = state.list![idx];
          return SingleSelectionCell(
            text: text,
            index: idx,
            isChoosed: state.idxs.contains(idx),
          );
        },
        separatorBuilder: (ctx, idx) {
          return Container(
            height: 0.5,
            color: const Color(0xfff0f2f5),
          );
        },
        itemCount: state.list?.length ?? 0);
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<SingleSelectionController>(
      builder: (_) {
        return Scaffold(
          appBar: detailAppBar(context, title: state.title, actions: [
            TextButton(
              onPressed: controller.actionSure,
              child: Text('确定'),
            ),
          ]),
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }
}
